package com.rran.study.designpattern.structural.composite;

import lombok.Data;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * @author yy
 * @Type PackageGoods.java
 * @Desc B袋子
 * @date 2020/7/24 17:28
 */
@Data
public class PackageB implements GoodsAction {

    private List<GoodsAction> goods = new ArrayList<>();

    @Override
    public void add(GoodsAction goods) {
        this.goods.add(goods);
    }

    @Override
    public void remove(GoodsAction goods) {
        this.goods.remove(goods);
    }

    @Override
    public BigDecimal acount() {
        BigDecimal price = BigDecimal.ZERO;
        if (!CollectionUtils.isEmpty(this.goods)) {
            for (GoodsAction g : goods) {
                price = price.add(g.acount());
            }
        }
        return price;
    }
}
